#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <queue>
using namespace std;
class A
{
public:
    bool operator()(long long x, long long y)
    {
        return x > y;
    }
};
int main()
{
    int n = 0;
    cin >> n;
    priority_queue<long long, vector<long long>, A> pq;
    long long tmp = 0;
    for (int i = 0;i < n;i++)
    {
        cin >> tmp;
        if (n == 1)
        {
            cout << tmp << endl;
            return 0;
        }
        pq.push(tmp);
    }
    long long count = 0;
    while (pq.size() > 1)
    {
        long long x = pq.top();
        pq.pop();
        long long y = pq.top();
        pq.pop();
        count += (x + y);
        pq.push(x + y);
    }
    cout << count << endl;
}
